
const PointerInteraction = ol.interaction.Pointer
export const Drag = /*@__PURE__*/(function (PointerInteraction) {
    function Drag() {
      PointerInteraction.call(this, {
        handleDownEvent: handleDownEvent,
        handleDragEvent: handleDragEvent,
        handleMoveEvent: handleMoveEvent,
        handleUpEvent: handleUpEvent,
      });
  
      /**
       * @type {import("../src/ol/coordinate.js").Coordinate}
       * @private
       */
      this.coordinate_ = null;
  
      /**
       * @type {string|undefined}
       * @private
       */
      this.cursor_ = 'pointer';
  
      /**
       * @type {Feature}
       * @private
       */
      this.feature_ = null;
  
      /**
       * @type {string|undefined}
       * @private
       */
      this.previousCursor_ = undefined;
    }
    
    if ( PointerInteraction ) Drag.__proto__ = PointerInteraction;
    Drag.prototype = Object.create( PointerInteraction && PointerInteraction.prototype );
    Drag.prototype.constructor = Drag;
  
    return Drag;
  }(PointerInteraction));
  
  /**
   * @param {import("../src/ol/MapBrowserEvent.js").default} evt Map browser event.
   * @return {boolean} `true` to start the drag sequence.
   */
  function handleDownEvent(evt) {
    var map = evt.map;
  
    var feature = map.forEachFeatureAtPixel(evt.pixel, function (feature) {
      return feature;
    });
  
    this.coordinate_[0] = evt.coordinate[0];
    this.coordinate_[1] = evt.coordinate[1];
  
    return !!feature;
  }
  
  /**
   * @param {import("../src/ol/MapBrowserEvent.js").default} evt Map browser event.
   */
  function handleDragEvent(evt) {
    var deltaX = evt.coordinate[0] - this.coordinate_[0];
    var deltaY = evt.coordinate[1] - this.coordinate_[1];
  
    var geometry = this.feature_.getGeometry();
    geometry.translate(deltaX, deltaY);
  
    this.coordinate_[0] = evt.coordinate[0];
    this.coordinate_[1] = evt.coordinate[1];
  }
  
  /**
   * @param {import("../src/ol/MapBrowserEvent.js").default} evt Event.
   */
  function handleMoveEvent(evt) {
    if (this.cursor_) {
      var map = evt.map;
      var feature = map.forEachFeatureAtPixel(evt.pixel, function (feature) {
        return feature;
      });
      var element = evt.map.getTargetElement();
      if (feature) {
        if (element.style.cursor != this.cursor_) {
          this.previousCursor_ = element.style.cursor;
          element.style.cursor = this.cursor_;
        }
      } else if (this.previousCursor_ !== undefined) {
        element.style.cursor = this.previousCursor_;
        this.previousCursor_ = undefined;
      }
    }
  }
  
  /**
   * @return {boolean} `false` to stop the drag sequence.
   */
  function handleUpEvent() {
    this.coordinate_ = null;
    this.feature_ = null;
    return false;
  }

  export const PointSelect = /*@__PURE__*/(function (PointerInteraction) {
    function PointSelect(point) {
      PointerInteraction.call(this, {
        handleDownEvent: handlePointSelectEvent,
      });
  
      /**
       * @type {import("../src/ol/coordinate.js").Coordinate}
       * @private
       */
      this.coordinate_ = null;
  
      /**
       * @type {string|undefined}
       * @private
       */
      this.cursor_ = 'pointer';
  
      /**
       * @type {Feature}
       * @private
       */
      this.point_ = point;
    }
    
    if ( PointerInteraction ) PointSelect.__proto__ = PointerInteraction;
    PointSelect.prototype = Object.create( PointerInteraction && PointerInteraction.prototype );
    PointSelect.prototype.constructor = PointSelect;
  
    return PointSelect;
  }(PointerInteraction));
  
  function handlePointSelectEvent(evt) {
    this.point_.setCoordinates(evt.coordinate)
    return false;
  }